package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.DaoShareConfigVO;
import com.sc.nft.enums.AwardsTypeEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.DaoShareConfig;
import com.sc.nft.mapper.DaoShareConfigMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 分红配置表(sc_dao_share_config)数据DAO
 *
 * @author zxy
 * @since 2023-12-14 16:20:11
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class DaoShareConfigDao extends ServiceImpl<DaoShareConfigMapper, DaoShareConfig> {


    public DaoShareConfig getByNameExceptId(String name,Long exceptId){
        LambdaQueryWrapper<DaoShareConfig> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(DaoShareConfig::getName,name);
        wrapper.ne(exceptId!=null,DaoShareConfig::getId,exceptId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public DaoShareConfig getByDaoIdAndCollectionIdAndTypeExceptId(Long daoId,Long identityCollectionId ,AwardsTypeEnum type, Long exceptId){
        LambdaQueryWrapper<DaoShareConfig> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(DaoShareConfig::getDaoId,daoId);
        wrapper.eq(identityCollectionId!=null,DaoShareConfig::getIdentityCollectionId,identityCollectionId);
        wrapper.eq(DaoShareConfig::getAwardsType,type);
        wrapper.ne(exceptId!=null,DaoShareConfig::getId,exceptId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public Page<DaoShareConfigVO> getConfigPage(Long daoId,String name,Boolean status,Page page){
        return baseMapper.getConfigPage(page,daoId,name,status);
    }

    public List<DaoShareConfig> getByOpenType(AwardsTypeEnum type){
        return lambdaQuery().eq(DaoShareConfig::getAwardsType,type).eq(DaoShareConfig::getStatus,true).list();
    }
    public List<DaoShareConfig> getOpenByDaoId(Long daoId){
        return lambdaQuery().eq(DaoShareConfig::getDaoId,daoId).eq(DaoShareConfig::getStatus,true).list();
    }
}